package com.zc.zby.basicframedemo.activity;

import android.databinding.ViewDataBinding;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;

import com.jude.easyrecyclerview.EasyRecyclerView;
import com.zc.zby.basicframedemo.R;
import com.zc.zby.basicframedemo.adapter.ContactAdapter;
import com.zc.zby.basicframedemo.base.BaseDataBindingActivity;
import com.zc.zby.basicframedemo.data.DataUtils;
import com.zc.zby.basicframedemo.databinding.ActivityDataBindingBinding;
import com.zc.zby.basicframedemo.model.UserModel;
import com.zc.zby.basicframedemo.present.DataBindPresent;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class DataBindingActivity extends BaseDataBindingActivity {

    @BindView(R.id.EasyRecyclerView)
    protected EasyRecyclerView mEasyRecyclerView;
    private ContactAdapter contactAdapter;
    private List<UserModel> userModels;

    @Override
    public int getLayoutId() {
        return R.layout.activity_data_binding;
    }

    @Override
    public void initViews(Bundle savedInstanceState) {
        userModels = new ArrayList<>();
        mEasyRecyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
        mEasyRecyclerView.setAdapter(contactAdapter = new ContactAdapter(getApplicationContext()));
        for (int i = 0; i < DataUtils.names.length; i++) {
            UserModel userModel = new UserModel();
            userModel.name.set(DataUtils.names[i]);
            userModel.phone.set(DataUtils.phones[i]);
            userModel.sex.set(DataUtils.sex[i]);
            userModels.add(userModel);
        }
        contactAdapter.addAll(userModels);
    }

    @Override
    public void initToolBar() {

    }

    @Override
    public void initData(ViewDataBinding viewDataBinding) {
        ((ActivityDataBindingBinding) viewDataBinding).setUserPresent(new DataBindPresent(contactAdapter));
    }

}
